package Main;

import Maze.Maze;
import Maze.Mouse;
import Tree.Node;

public class GoalTestMouseInAMaze implements GoalTest {

	/**
	 * 
	 * @param node
	 *            which is to be tested if the state inside it is the goal test
	 *            or not, the mouse's position is extracted from the maze in the
	 *            node and all the positions after the mouse are checked to see
	 *            if they are empty or not
	 * @return whether it is a goal or not
	 */
	
	public boolean goalTest(Node node) {

		Maze currentMaze = (Maze) node.getState();
		Mouse mouse = currentMaze.getMouse();
		boolean hit = false;
		int endX = mouse.getEndX();

		if (endX == 5) {

			return true;

		} else if (endX < 5) {

			for (int i = 1; i < (6 - endX); i++) {

				if (!currentMaze.getGrid()[endX + i][2].equals(". ")) {
					return false;

				}
			}
		}

		if (!hit) {
			return true;
		}

		return false;
	}

}
